<style lang="less" scoped>

  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }

  .f-w70 {
    width: 70%;
  }
</style>

<template>
  <section>
    <!--工具条-->
    <search-bar more-display>
      <el-row>
        <el-col :span="8">
          <el-form-item label="承运商名称">
            <el-input  v-model="searchCondition.LIKE_commonCarrierName" placeholder="请输入承运商名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="负责人">
            <el-input  v-model="searchCondition.LIKE_principal" placeholder="请输入负责人"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="手机号">
            <el-input  v-model="searchCondition.LIKE_phone" placeholder="请输入手机号"></el-input>
          </el-form-item>
        </el-col>

      </el-row>
    </search-bar>

    <!-- 操作 -->
    <el-col :span="24" style="margin-bottom: 10px">
      <el-button type="primary" @click="handleAdd">新增</el-button>
      <el-button type="primary" @click="myResert" style="float: right">重置</el-button>
      <el-button type="primary" @click="searchServiceProvider" style="float: right">查询</el-button>
    </el-col>

    <!--列表-->
    <el-table :data="tableData" highlight-current-row border @sort-change="sortChange" max-height="650"
              @selection-change="selsChange" v-loading="listLoading" style="width: 100%;">
      <el-table-column type="index" label="序号" width="80">
      </el-table-column>
      <el-table-column prop="statusName" label="状态" width="80">
      </el-table-column>
      <el-table-column prop="typeName" label="类型" width="80">
      </el-table-column>
      <el-table-column prop="commonCarrierName" label="承运商" width="200" >
      </el-table-column>
      <el-table-column prop="principal" label="负责人" width="120" >
      </el-table-column>
      <el-table-column prop="phone" label="电话" width="130" >
      </el-table-column>
      <el-table-column prop="commonCarrierId" label="承运商账号" width="150" >
      </el-table-column>
      <el-table-column prop="addressAll" label="运输范围包含" width="220">
      </el-table-column>
      <el-table-column prop="notAddressAll" label="运输范围不包含" width="220">
      </el-table-column>
      <el-table-column prop="remark" label="备注" >
      </el-table-column>

      <el-table-column fixed="right" label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button type="success" v-if="scope.row.status===111002002"
                     @click="handleStart(scope.$index, scope.row)">启用

          </el-button>
          <el-button type="warning" v-if="scope.row.status===111002001"
                     @click="handleStop(scope.$index, scope.row)">停用

          </el-button>
          <el-button  type="primary" @click="getEditBYId(scope.$index, scope.row)">编辑 </el-button>
          <el-button type="danger"  @click="handleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination
        :current-page="currentPage"
        :page-size="pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next, jumper"
        :total="total" style="float: right">
      </el-pagination>
    </el-col>

    <!-- 弹窗 -->
    <el-dialog :title="dialogTitle" size="tiny" :visible.sync="serviceProviderVisible" :close-on-click-modal="false">
      <el-form :model="serviceProvider" :rules="rules" label-width="100px" ref="serviceProvider">
        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="承运商类型" class="width70" prop="type">
              <el-select  v-model="serviceProvider.type"
                         placeholder="请选择">
                <el-option
                  v-for="item in $store.getters.RPOVIDER_COMPANY_TYPE"
                  :key="item.dictVal"
                  :label="item.cnDictValname"
                  :value="item.dictVal">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="承运商名称" class="width70" prop="commonCarrierName">
              <el-input v-model="serviceProvider.commonCarrierName"
                        placeholder="请输入承运商名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="承运商账号" class="width70" prop="commonCarrierId">
              <el-input v-model="serviceProvider.commonCarrierId" placeholder="请输入承运商账号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="归属组织" prop="organizationId1">
              <el-cascader
                placeholder="请选择归属组织"
                :options="$store.state.initOrganizations"
                :props="{label: 'name',value: 'id'}"
                change-on-select
                v-model="serviceProvider.organizationId1"
              ></el-cascader>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="负责人" class="width70" prop="principal">
              <el-input v-model="serviceProvider.principal" placeholder="请输入负责人"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="手机" class="width70" prop="phone">
              <el-input type="number" v-model="serviceProvider.phone" placeholder="请输入手机号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item>
          <el-button  type="primary" @click="addIncludeArea()" style="float: right">新增</el-button>
        </el-form-item>

        <el-form-item label="范围">
          <el-table
            :data="tableDataGO"
            style="width: 400%">
            <el-table-column
              prop="province"
              label="包含省"
              width="150">
            </el-table-column>
            <el-table-column
              prop="city"
              label="包含市"
              width="150">
            </el-table-column>
            <el-table-column
              prop="county"
              label="包含区">
            </el-table-column>
            <el-table-column
              prop="notincludeProvince"
              label="不包含省"
              width="150">
            </el-table-column>
            <el-table-column
              prop="notincludeCity"
              label="不包含市"
              width="150">
            </el-table-column>
            <el-table-column
              width="180"
              prop="notincludeCounty"
              label="不包含区">
            </el-table-column>

            <el-table-column label="操作" width="150">
              <template slot-scope="scope">
                <el-button  type="primary"
                           @click="getEditAddressBYId(scope.$index, scope.row)">编辑
                </el-button>
                <el-button type="danger"
                           @click.native.prevent="handleAddressDel(scope.$index,scope.row.id , tableDataGO)"
                >删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>

        </el-form-item>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="备注" class="width70" prop="remark">
              <el-input 备注 v-model="serviceProvider.remark" placeholder="请输入备注"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelAddress">取消</el-button>
        <el-button type="primary" @click="saveServiceProviders" :loading="submitLoading">提交</el-button>
      </div>
    </el-dialog>

    <!-- 地址弹窗 -->
    <el-dialog :title="includeTitle"  :visible.sync="myIncludeAreaVisible" :close-on-click-modal="false">
      <el-form :model="myIncludeArea" label-width="90px" ref="myIncludeArea">
        <el-form-item label="包含省">
          <el-select clearable  v-model="myIncludeArea.province" @change="myProvince"
                     @clear="myProvinceClear"
                     value-key="id"
                     placeholder="请选择省">
            <el-option
              v-for="item in includeProvinceValue"
              :key="item.id"
              :label="item.name"
              :value="item">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="包含市">
          <el-select clearable  v-model="myIncludeArea.provinceAndCity"
                     value-key="id"
                     @clear="myIncludeProvinceClear" @change="myIncludeProvince" placeholder="请选择省">
            <el-option
              v-for="item in provinceAndCityIdValue"
              :key="item.id"
              :label="item.name"
              :value="item">
            </el-option>
          </el-select>

          <el-select clearable v-model="myIncludeArea.city"
                     @clear="myProvinceAndCityClear"
                     value-key="id"
                     @change="myProvinceAndCity" placeholder="请选择市">
            <el-option
              v-for="item in includeCityValue"
              :key="item.id"
              :label="item.name"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="包含区">
          <el-select clearable  v-model="myIncludeArea.provinceAndCityAndCounry"
                     @change="includeProvinceAndCityAndCounry"
                     value-key="id"
                     @clear="includeProvinceAndCityAndCounryClear"
                     placeholder="请选择省">
            <el-option
              v-for="item in provinceAndCityAndCounryValue"
              :key="item.id"
              :label="item.name"
              :value="item"
            >
            </el-option>
          </el-select>

          <el-select clearable v-model="myIncludeArea.cityAndCounry"
                     @clear="includeCityClear"
                     value-key="id"
                     @change="includeCity" placeholder="请选择市">
            <el-option
              v-for="item in includeCityAndCounryValue"
              :key="item.id"
              :label="item.name"
              :value="item"
            >
            </el-option>
          </el-select>
          <el-select clearable v-model="myIncludeArea.county" @change="myIncludeCityAndCounty"
                     @clear="myIncludeCityAndCountyClear"
                     value-key="id"
                     placeholder="请选择区/县">
            <el-option
              v-for="item in includeCountyValue"
              :key="item.id"
              :label="item.name"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="不包含省">
          <el-select clearable  @change="myNotIncludeProvince"
                     @clear="myNotIncludeProvinceClear"
                     value-key="id"
                     v-model="myIncludeArea.notincludeProvince"
                     placeholder="请选择省">
            <el-option
              v-for="item in notIncludeProvinceValue"
              :key="item.id"
              :label="item.name"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="不包含市">
          <el-select clearable  v-model="myIncludeArea.notincludeProvinceAndCity"
                     @change="notIncludeProvinceAndCity"
                     @clear="notIncludeProvinceAndCityClear"
                     value-key="id"
                     placeholder="请选择省">
            <el-option
              v-for="item in notIncludeProvinceAndCityIdValue"
              :key="item.id"
              :label="item.name"
              :value="item"
            >
            </el-option>
          </el-select>
          <el-select clearable v-model="myIncludeArea.notincludeCity"
                     @change="myNotIncludeCity"
                     @clear="myNotIncludeCityClear"
                     value-key="id"
                     placeholder="请选择市">
            <el-option
              v-for="item in notIncludeCityValue"
              :key="item.id"
              :label="item.name"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="不包含区">
          <el-select clearable  v-model="myIncludeArea.notincludeProvinceAndCityAndCounry"
                     @change="notIncludeProvinceAndCityAndCounry"
                     @clear="notIncludeProvinceAndCityAndCounryClear"
                     value-key="id"
                     placeholder="请选择省">
            <el-option
              v-for="item in notIncludeprovinceAndCityAndCounryValue"
              :key="item.id"
              :label="item.name"
              :value="item"
            >
            </el-option>
          </el-select>

          <el-select clearable v-model="myIncludeArea.notincludeCityAndCounry"
                     @change="notIncludeCityAndCounry"
                     @clear="notIncludeCityAndCounryClear"
                     value-key="id"
                     placeholder="请选择市">
            <el-option
              v-for="item in notincludeCityAndCounryValue"
              :key="item.id"
              :label="item.name"
              :value="item"
            >
            </el-option>
          </el-select>
          <el-select clearable v-model="myIncludeArea.notincludeCounty  "
                     @change="myIncludeCounty"
                     @clear="myIncludeCountyClear"
                     value-key="id"
                     placeholder="请选择区/县">
            <el-option
              v-for="item in notIncludeCountyValue"
              :key="item.id"
              :label="item.name"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="myIncludeAreaVisible = false">取消</el-button>
        <el-button type="primary" @click="myAreaSave">提交</el-button>
      </div>
    </el-dialog>

  </section>
</template>

<script>
import {
  searchServiceProvider,
  saveServiceProvider,
  resetStatus,
  batchDel
} from '../../api/cap/serviceprovider.js';
import {objToFilter, resetObjNull, isEmpty} from '../../lib/util';
import {
  getAddresses
} from '../../api/system/MarkCargo';
export default {
  data () {
    return {
      searchCondition: {
        LIKE_commonCarrierName: null,
        LIKE_principal: null,
        LIKE_phone: null
      },
      currentDelId: [], // 记录范围删除的ID
      currentIndex: '',
      currentRowId: '', // 当前的ROWID
      currentRow: '', // 当前的ROWID
      tableDataGO: [],
      organization1: '',
      stowageCore1: '',
      cargoType: [], // 大画面的提货类型类型
      isStart: [], // 大画面的类型类型
      organizationValue: [], // 调度中心
      stowageValue: [], // 配载中心
      includeProvinceValue: [], // 包含省
      provinceAndCityIdValue: [], // 包含省-有市
      provinceAndCityAndCounryValue: [], // 包含省-有市 -有区
      includeCityValue: [], // 包含城市
      includeCityAndCounryValue: [], // 包含城-区
      includeCountyValue: [], // 包含区/县
      notIncludeProvinceValue: [], // 不包含省
      notIncludeProvinceAndCityIdValue: [], // 不包含省 有--市
      notIncludeprovinceAndCityAndCounryValue: [], // 不包含省 有--市 --区
      notIncludeCityValue: [], // 不包含城市
      notincludeCityAndCounryValue: [], // 不包含城市有区
      notIncludeCountyValue: [], // 不包含区/县
      stowageCoreCenter2: [],
      searchStowageCoreCenter2: [],
      searchBarOrganization2: [],
      controlCenter2: [],
      searchBarStowageCore: [],

      props: {
        label: 'name',
        value: 'id',
        children: 'children'
      },
      props1: {
        label: 'name',
        value: 'id',
        children: 'children'
      },

      searchStowageCoreprops: {
        label: 'name',
        value: 'id',
        children: 'children'
      },

      searchBarOrgazizationprops: {
        label: 'name',
        value: 'id',
        children: 'children'
      },

      dialogTitle: '新增',
      condition: {
        name: '',
        number: ''
      },

      includeTitle: '新增地址', // 新增地址标题
      sels: [],
      tableData: [],
      total: 0,
      currentPage: 1,
      pageSize: 10,
      sortProp: null,
      sortOrder: 'ascending',
      listLoading: false,
      serviceProviderVisible: false,
      myIncludeAreaVisible: false,
      submitLoading: false,

      connectionTyperadio: '',
      // 表单数据
      serviceProvider: {
        'id': null,
        'type': null,
        'serviceProviderOrganizationId': null,
        'status': null,
        'commonCarrierName': null,
        'principal': null,
        phone: '',
        'organizationId': null,
        'organizationId1': null,
        'remark': null,
        'tableDataGO': [],
        'ids': [],
        'commonCarrierId': null,
        // 表单数据
        myIncludeArea: {
          'id': null,
          'notincludeProvince': null,
          'notincludeProvinceId': null,

          'notincludeProvinceAndCity': null,
          'notincludeProvinceAndCityId': null,

          'notincludeProvinceAndCityAndCounry': null,
          'notincludeProvinceAndCityAndCounryId': null,

          'notincludeCity': null,
          'notincludeCityId': null,

          'notincludeCityAndCounry': null,
          'notincludeCityAndCounryId': null,

          'notincludeCounty': null,
          'notincludeCountyId': null,

          'province': null,
          'provinceId': null,

          'provinceAndCity': null,
          'provinceAndCityId': null,

          'provinceAndCityAndCounry': null,
          'provinceAndCityAndCounryId': null,

          'city': null,
          'cityId': null,

          'cityAndCounry': null,
          'cityAndCounryId': null,

          'county': null,
          'countyId': null,

          'markCargoId': null

        }
      },

      // 表单数据
      myIncludeArea: {
        'id': null,
        'notincludeProvince': null,
        'notincludeProvinceId': null,

        'notincludeProvinceAndCity': null,
        'notincludeProvinceAndCityId': null,

        'notincludeProvinceAndCityAndCounry': '',
        'notincludeProvinceAndCityAndCounryId': null,

        'notincludeCity': null,
        'notincludeCityId': null,

        'notincludeCityAndCounry': null,
        'notincludeCityAndCounryId': null,

        'notincludeCounty': null,
        'notincludeCountyId': null,

        'province': null,
        'provinceId': null,

        'provinceAndCity': null,
        'provinceAndCityId': null,

        'provinceAndCityAndCounry': null,
        'provinceAndCityAndCounryId': null,

        'city': null,
        'cityId': null,

        'cityAndCounry': null,
        'cityAndCounryId': null,

        'county': null,
        'countyId': null,

        'markCargoId': null

      },

      // 验证规则
      rules: {
        commonCarrierName: [
          {required: true, message: '请输入承运商名称', trigger: 'blur'},
          {min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur'}
        ],
        commonCarrierId: [
          {required: true, message: '请输入承运商账号', trigger: 'blur'},
          {min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur'}
        ],
        type: [
          {required: true, type: 'number', message: '请选择承运商类型', trigger: 'change'}
        ],
        phone: [
          {required: true, message: '请输入手机号', trigger: 'change'},
          {min: 11, max: 11, message: '长度在 11 个字符', trigger: 'change'}
        ],
        principal: [
          {required: true, message: '请输入负责人', trigger: 'change'},
          {min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur'}
        ],
        organizationId1: [
          {required: true, type: 'array', message: '请选择归属组织', trigger: 'change'}
        ]
      }
    };
  },
  methods: {
    myProvinceClear () {
      this.serviceProvider.myIncludeArea.province = null;
      this.serviceProvider.myIncludeArea.provinceId = null;
    },
    // 包含省有市-  省-选择时触 发 清空
    myIncludeProvinceClear () {
      this.serviceProvider.myIncludeArea.provinceAndCity = null;
      this.serviceProvider.myIncludeArea.provinceAndCityId = null;
    },
    //  包含省市 里的市 清空
    myProvinceAndCityClear () {
      this.serviceProvider.myIncludeArea.city = null;
      this.serviceProvider.myIncludeArea.cityId = null;
    },

    // 清空 --包含省有市有区-  省选择时触 发
    includeProvinceAndCityAndCounryClear () {
      this.serviceProvider.myIncludeArea.provinceAndCityAndCounry = null;
      this.serviceProvider.myIncludeArea.provinceAndCityAndCounryId = null;
    },

    //  清空 包含省-有市有区   市 选择时触 发
    includeCityClear () {
      this.serviceProvider.myIncludeArea.cityAndCounry = null;
      this.serviceProvider.myIncludeArea.cityAndCounryId = null;
    },
    // 清空  包含省-有市有区   区 选择时触 发
    myIncludeCityAndCountyClear () {
      this.serviceProvider.myIncludeArea.county = null;
      this.serviceProvider.myIncludeArea.countyId = null;
    },

    // 清空 --，不包含省
    myNotIncludeProvinceClear () {
      this.serviceProvider.myIncludeArea.notincludeProvince = null;
      this.serviceProvider.myIncludeArea.notincludeProvinceId = null;
    },

    // 清空 --不包含省有市-  省-选择时触 发
    notIncludeProvinceAndCityClear () {
      this.serviceProvider.myIncludeArea.notincludeProvinceAndCity = null;
      this.serviceProvider.myIncludeArea.notincludeProvinceAndCityId = null;
    },

    // 清空 --不包含省有市 ---市 选择
    myNotIncludeCityClear () {
      this.serviceProvider.myIncludeArea.notincludeCity = null;
      this.serviceProvider.myIncludeArea.notincludeCityId = null;
    },
    // 清空  不包含省份有市有区   省选择时触 发
    notIncludeProvinceAndCityAndCounryClear () {
      this.serviceProvider.myIncludeArea.notincludeProvinceAndCityAndCounry = null;
      this.serviceProvider.myIncludeArea.notincludeProvinceAndCityAndCounryId = null;
    },
    // 清空--不包含城市选择时触 发
    notIncludeCityAndCounryClear () {
      this.serviceProvider.myIncludeArea.notincludeCityAndCounry = null;
      this.serviceProvider.myIncludeArea.notincludeCityAndCounryId = null;
    },

    myIncludeCountyClear () {
      this.serviceProvider.myIncludeArea.notincludeCounty = null;
      this.serviceProvider.myIncludeArea.notincludeCountyId = null;
    },
    //  赋值--包含省
    myProvince (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.province = event.name;
        this.serviceProvider.myIncludeArea.provinceId = event.id;
      }
    },

    // 包含省有市-  省-选择时触 发
    myIncludeProvince (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.provinceAndCity = event.name;
        this.serviceProvider.myIncludeArea.provinceAndCityId = event.id;
        getAddresses(event.id).then((res) => {
          if (res.data.detailModelList !== '' && res.data.detailModelList !== null) {
            this.includeCityValue = res.data.detailModelList;
          }
        });
      }
    },
    // 赋值 --包含省市 里的市
    myProvinceAndCity (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.city = event.name;
        this.serviceProvider.myIncludeArea.cityId = event.id;
      }
    },
    // 赋值 --包含省有市有区-  省选择时触 发
    includeProvinceAndCityAndCounry (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.provinceAndCityAndCounry = event.name;
        this.serviceProvider.myIncludeArea.provinceAndCityAndCounryId = event.id;
        getAddresses(event.id).then((res) => {
          if (res.data.detailModelList !== '' && res.data.detailModelList !== null) {
            this.includeCityAndCounryValue = res.data.detailModelList;
          }
        });
      }
    },
    // 赋值  包含省-有市有区   市 选择时触 发
    includeCity (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.cityAndCounry = event.name;
        this.serviceProvider.myIncludeArea.cityAndCounryId = event.id;
        getAddresses(event.id).then((res) => {
          if (res.data.detailModelList !== '' && res.data.detailModelList !== null) {
            this.includeCountyValue = res.data.detailModelList;
          }
        });
      }
    },
    // 赋值  包含省-有市有区   区 选择时触 发
    myIncludeCityAndCounty (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.county = event.name;
        this.serviceProvider.myIncludeArea.countyId = event.id;
      }
    },

    // 赋值 --，不包含省
    myNotIncludeProvince (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.notincludeProvince = event.name;
        this.serviceProvider.myIncludeArea.notincludeProvinceId = event.id;
      }
    },

    // 赋值--不包含省有市-  省-选择时触 发
    notIncludeProvinceAndCity (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.notincludeProvinceAndCity = event.name;
        this.serviceProvider.myIncludeArea.notincludeProvinceAndCityId = event.id;
        getAddresses(event.id).then((res) => {
          if (res.data.detailModelList !== '' && res.data.detailModelList !== null) {
            this.notIncludeCityValue = res.data.detailModelList;
          }
        });
      }
    },
    // 赋值 --不包含省有市 ---市 选择
    myNotIncludeCity (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.notincludeCity = event.name;
        this.serviceProvider.myIncludeArea.notincludeCityId = event.id;
      }
    },
    // 赋值  不包含省份有市有区   省选择时触 发
    notIncludeProvinceAndCityAndCounry (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.notincludeProvinceAndCityAndCounry = event.name;
        this.serviceProvider.myIncludeArea.notincludeProvinceAndCityAndCounryId = event.id;
        getAddresses(event.id).then((res) => {
          if (res.data.detailModelList !== '' && res.data.detailModelList !== null) {
            this.notincludeCityAndCounryValue = res.data.detailModelList;
          }
        });
      }
    },
    // 赋值--不包含城市选择时触 发
    notIncludeCityAndCounry (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.notincludeCityAndCounry = event.name;
        this.serviceProvider.myIncludeArea.notincludeCityAndCounryId = event.id;
        getAddresses(event.id).then((res) => {
          if (res.data.detailModelList !== '' && res.data.detailModelList !== null) {
            this.notIncludeCountyValue = res.data.detailModelList;
          }
        });
      }
    },

    myIncludeCounty (event) {
      if (event) {
        this.serviceProvider.myIncludeArea.notincludeCounty = event.name;
        this.serviceProvider.myIncludeArea.notincludeCountyId = event.id;
      }
    },

    // 地址重置
    myAddressRest () {
      this.myIncludeArea.provinceId = '';
      this.myIncludeArea.provinceAndCityId = '';
      this.myIncludeArea.cityId = '';
      this.myIncludeArea.provinceAndCityAndCounryId = '';
      this.myIncludeArea.cityAndCounryId = '';
      this.myIncludeArea.countyId = '';

      this.myIncludeArea.notincludeProvinceId = '';
      this.myIncludeArea.notincludeProvinceAndCityId = '';
      this.myIncludeArea.notincludeCityId = '';
      this.myIncludeArea.notincludeProvinceAndCityAndCounryId = '';
      this.myIncludeArea.notincludeCityAndCounryId = '';
      this.myIncludeArea.notincludeCountyId = '';
    },

    // 新增时取消短驳时的方法
    cancelAddress () {
      this.serviceProviderVisible = false;
    },

    // 保存地址
    myAreaSave () {
      if (isEmpty(this.serviceProvider.myIncludeArea.province) && isEmpty(this.serviceProvider.myIncludeArea.city) && isEmpty(this.serviceProvider.myIncludeArea.county) && isEmpty(this.serviceProvider.myIncludeArea.notincludeProvince) && isEmpty(this.serviceProvider.myIncludeArea.notincludeCity) && isEmpty(this.serviceProvider.myIncludeArea.notincludeCounty)) {
        this.$message.error('请至少选择一项地址！');
        return;
      }
      let routeFreightNew = '';
      if (this.tableDataGO.length > 0) {
        for (let x = 0; x < this.tableDataGO.length; x++) {
          if (this.currentRowId === this.tableDataGO[x].id) {
            this.tableDataGO.splice(this.currentIndex, 1);
            routeFreightNew = Object.assign({
              'id': null,
              'notincludeProvince': null,
              'notincludeProvinceId': null,

              'notincludeProvinceAndCity': null,
              'notincludeProvinceAndCityId': null,

              'notincludeProvinceAndCityAndCounry': null,
              'notincludeProvinceAndCityAndCounryId': null,

              'notincludeCity': null,
              'notincludeCityId': null,

              'notincludeCityAndCounry': null,
              'notincludeCityAndCounryId': null,

              'notincludeCounty': null,
              'notincludeCountyId': null,

              'province': '',
              'provinceId': '',

              'provinceAndCity': null,
              'provinceAndCityId': null,

              'provinceAndCityAndCounry': null,
              'provinceAndCityAndCounryId': null,

              'city': null,
              'cityId': null,

              'cityAndCounry': null,
              'cityAndCounryId': null,

              'county': null,
              'countyId': null,

              'markCargoId': null
            }, this.serviceProvider.myIncludeArea);
          } else {
            routeFreightNew = Object.assign({
              'id': null,
              'notincludeProvince': null,
              'notincludeProvinceId': null,

              'notincludeProvinceAndCity': null,
              'notincludeProvinceAndCityId': null,

              'notincludeProvinceAndCityAndCounry': null,
              'notincludeProvinceAndCityAndCounryId': null,

              'notincludeCity': null,
              'notincludeCityId': null,

              'notincludeCityAndCounry': null,
              'notincludeCityAndCounryId': null,

              'notincludeCounty': null,
              'notincludeCountyId': null,

              'province': '',
              'provinceId': '',

              'provinceAndCity': null,
              'provinceAndCityId': null,

              'provinceAndCityAndCounry': null,
              'provinceAndCityAndCounryId': null,

              'city': null,
              'cityId': null,

              'cityAndCounry': null,
              'cityAndCounryId': null,

              'county': null,
              'countyId': null,

              'markCargoId': null
            }, this.serviceProvider.myIncludeArea);
          }
        }
      } else {
        routeFreightNew = Object.assign({
          'id': null,
          'notincludeProvince': null,
          'notincludeProvinceId': null,

          'notincludeProvinceAndCity': null,
          'notincludeProvinceAndCityId': null,

          'notincludeProvinceAndCityAndCounry': null,
          'notincludeProvinceAndCityAndCounryId': null,

          'notincludeCity': null,
          'notincludeCityId': null,

          'notincludeCityAndCounry': null,
          'notincludeCityAndCounryId': null,

          'notincludeCounty': null,
          'notincludeCountyId': null,

          'province': '',
          'provinceId': '',

          'provinceAndCity': null,
          'provinceAndCityId': null,

          'provinceAndCityAndCounry': null,
          'provinceAndCityAndCounryId': null,

          'city': null,
          'cityId': null,

          'cityAndCounry': null,
          'cityAndCounryId': null,

          'county': null,
          'countyId': null,

          'markCargoId': null
        }, this.serviceProvider.myIncludeArea);
      }
      this.tableDataGO.push(routeFreightNew);
      console.log(this.tableDataGO);
      this.myIncludeAreaVisible = false;
    },

    // 打开地址界面
    addIncludeArea () {
      this.myAddressRest();
      // this.resetForm1();
      this.addGetAddress();
      this.currentRowId = 123456789;
      this.includeTitle = '新增地址';
      this.serviceProvider.myIncludeArea = {};
      this.myIncludeAreaVisible = true;
    },

    // 搜索
    searchServiceProvider () {
      this.loadingLists(objToFilter(this.searchCondition));
    },
    loadingLists (filter) {
      this.listLoading = true;
      searchServiceProvider({
        filters: filter,
        size: this.pageSize,
        page: this.currentPage,
        sorts: (this.sortProp === null ? '' : (this.sortOrder === 'ascending' ? '-' : '+') + this.sortProp)
      }).then(res => {
        if (res.data.successFlg) {
          this.tableData = res.data.detailModelList;
          this.currentPage = res.data.currPage;
          this.total = res.data.totalCount;
          this.pageSize = res.data.pageSize;
          this.listLoading = false;
        }
      });
    },
    // 搜索栏重置
    myResert () {
      resetObjNull(this.searchCondition);
    },

    // 打开编辑界面
    getEditBYId (index, row) {
      if (row.status === 111002001) {
        return this.$message.error('已启用，无法编辑!');
      }
      this.serviceProvider = Object.assign({}, row);
      this.serviceProvider.organizationId1 = row.serviceProviderOrganizationId.split(',');
      this.tableDataGO = [];
      this.tableDataGO = row.serviceProviderAreaList;
      this.dialogTitle = '修改';
      this.serviceProviderVisible = true;
    },

    // 打开短驳地址编辑界面
    getEditAddressBYId (index, row) {
      this.myAddressRest();
      this.resetForm1();
      this.addGetAddress();
      this.currentRowId = row.id;
      this.currentRow = row;
      this.currentIndex = index;
      this.dialogTitle = '地址修改';
      this.serviceProvider.myIncludeArea = Object.assign({}, row);
      this.myIncludeArea = Object.assign({
        'id': null,
        'notincludeProvince': null,
        'notincludeProvinceId': null,

        'notincludeProvinceAndCity': null,
        'notincludeProvinceAndCityId': null,

        'notincludeProvinceAndCityAndCounry': null,
        'notincludeProvinceAndCityAndCounryId': null,

        'notincludeCity': null,
        'notincludeCityId': null,

        'notincludeCityAndCounry': null,
        'notincludeCityAndCounryId': null,

        'notincludeCounty': null,
        'notincludeCountyId': null,

        'province': null,
        'provinceId': null,

        'provinceAndCity': null,
        'provinceAndCityId': null,

        'provinceAndCityAndCounry': null,
        'provinceAndCityAndCounryId': null,

        'city': null,
        'cityId': null,

        'cityAndCounry': null,
        'cityAndCounryId': null,

        'county': null,
        'countyId': null,

        'markCargoId': null
      }, row);
      this.myIncludeAreaVisible = true;
    },

    // 删除单条数据操作
    handleDel (index, row) {
      if (row.status === 111002001) {
        return this.$message.error('已启用，无法删除!');
      }
      this.$confirm('确认删除该承运商吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        batchDel(row.id).then((res) => {
          this.listLoading = false;
          this.$message({
            message: '删除成功！',
            type: 'success'
          });
          this.currentPage = 1;
          this.searchServiceProvider();
        });
      }).catch(() => {
      });
    },

    // 删除单条短驳地址数据操作
    handleAddressDel (index, id, row) {
      if (!isEmpty(id)) {
        this.currentDelId.push(id);
      }
      console.log(this.currentDelId);
      row.splice(index, 1);
    },
    // 单 条启用
    handleStart (index, row) {
      this.$confirm('确认启用该承运商吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        let isStart = 111002001;
        resetStatus(row.id, isStart).then((res) => {
          this.listLoading = false;
          this.$message({
            message: '启用成功！',
            type: 'success'
          });
          this.searchServiceProvider();
        });
      }).catch(() => {
      });
    },

    // 单 条停用
    handleStop (index, row) {
      this.$confirm('确认停用该承运商吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        let isStart = 111002002;
        resetStatus(row.id, isStart).then((res) => {
          this.listLoading = false;
          this.$message({
            message: '停用成功！',
            type: 'success'
          });
          this.searchServiceProvider();
        });
      }).catch(() => {
      });
    },
    // 新增修改数据提交
    saveServiceProviders () {
      this.$refs['serviceProvider'].validate((valid) => {
        if (valid) {
          this.serviceProvider.serviceProviderOrganizationId = this.serviceProvider.organizationId1.join(',');
          this.serviceProvider.tableDataGO = this.tableDataGO;
          this.submitLoading = true;
          this.serviceProvider.ids = this.currentDelId;
          saveServiceProvider(this.serviceProvider).then((res) => {
            this.submitLoading = false;
            if (res.data.successFlg === true) {
              this.serviceProviderVisible = false;
              this.getTableData();
              this.$message.success('保存/修改成功！');
            } else {
              this.$message.error(res.data.errorMsg);
            }
          });
        } else {
          return false;
        }
      });
    },
    // 重置表单
    resetForm () {
      if (this.$refs.serviceProvider) {
        this.$refs.serviceProvider.resetFields();
      }
      // 当先点击修改，再点击新增，会出现值没有清空,修复处理
      for (let p in this.serviceProvider) {
        if (this.serviceProvider[p] instanceof Array) {
          this.serviceProvider[p] = [];
        } else {
          this.serviceProvider[p] = null;
        }
      }
    },
    // 重置表单
    resetForm1 () {
      if (this.$refs.serviceProvider) {
        this.$refs.serviceProvider.resetFields();
      }
      if (this.$refs.myIncludeArea) {
        this.$refs.myIncludeArea.resetFields();
      }
      // 当先点击修改，再点击新增，会出现值没有清空,修复处理
      for (let p in this.serviceProvider) {
        if (this.serviceProvider[p] instanceof Array) {
          this.serviceProvider[p] = [];
        } else {
          this.serviceProvider[p] = null;
        }
      }
      for (let p in this.myIncludeArea) {
        if (this.myIncludeArea[p] instanceof Array) {
          this.myIncludeArea[p] = [];
        } else {
          this.myIncludeArea[p] = null;
        }
      }
    },
    // 弹出添加窗体
    handleAdd () {
      this.tableDataGO = [];
      this.dialogTitle = '新增';
      this.resetForm();
      this.serviceProviderVisible = true;
    },

    // 多选操作
    selsChange (sels) {
      this.sels = sels;
    },
    // 排序操作
    sortChange (o) {
      this.sortProp = o.prop;
      this.sortOrder = o.order;
      this.searchServiceProvider();
    },
    // 每页几条操作
    handleSizeChange (val) {
      this.pageSize = val;
      this.searchServiceProvider();
    },
    // 第几页操作
    handleCurrentChange (val) {
      this.currentPage = val;
      this.searchServiceProvider();
    },
    // 重置查询条件
    resetCondition () {
      for (let p in this.condition) {
        this.condition[p] = null;
      }
    },

    // 获取表格数据
    getTableData () {
      this.listLoading = true;
      searchServiceProvider({
        page: this.currentPage,
        size: this.pageSize,
        filters: '',
        sorts: (this.sortProp === null ? '' : (this.sortOrder === 'ascending' ? '-' : '+') + this.sortProp)
      }).then((res) => {
        if (res.data.successFlg) {
          this.tableData = res.data.detailModelList;
          this.currentPage = res.data.currPage;
          this.total = res.data.totalCount;
          this.pageSize = res.data.pageSize;
          this.listLoading = false;
        } else {
          this.$message.error(res.data.errorMsg);
        }
      });
    },
    addGetAddress () {
      // 初始化载入省份
      getAddresses('156').then((res) => {
        if (res.data.detailModelList !== '' && res.data.detailModelList !== null) {
          this.includeProvinceValue = res.data.detailModelList;
          this.provinceAndCityIdValue = res.data.detailModelList;
          this.provinceAndCityAndCounryValue = res.data.detailModelList;

          this.notIncludeProvinceValue = res.data.detailModelList;
          this.notIncludeProvinceAndCityIdValue = res.data.detailModelList;
          this.notIncludeprovinceAndCityAndCounryValue = res.data.detailModelList;
        }
      });
    }
  },
  // 初始化数据
  mounted () {
    // 初始化载入表格
    this.getTableData();
    this.$store.commit('initDict');
    this.$store.commit('initOrganizations');
  }
};
</script>

<style lang="less" scoped>

</style>
